package com.rainbow.support.message.notify.properties;

import lombok.*;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 傅为地
 * 用户操作自定义日志配置项
 */
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@ConfigurationProperties(prefix = MessageProperties.EXTRA_MESSAGE_NOTIFY_PREFIX)
public class MessageProperties {

    /**
     * 邮件配置
     */
    public static final String EXTRA_MESSAGE_NOTIFY_PREFIX = "rainbow.extra.message.notify";


    /**
     * 邮件配置前缀
     */
    public static final String EXTRA_MESSAGE_NOTIFY_EMAIL_SPEL = "${rainbow.extra.message.notify.mail.enable:true}";

    /**
     * 钉钉配置前缀
     */
    public static final String EXTRA_MESSAGE_NOTIFY_DING_SPEL = "${rainbow.extra.message.notify.ding.enable:true}";

    /**
     * 是否开启通知
     */
    private boolean enable = true;


    /**
     * 邮件通知
     */
    private Mail mail = new Mail();

    @Data
    public class Mail {

        /**
         * 是否开启
         */
        private boolean enable = true;

        /**
         * SMTP server host. For instance, `smtp.example.com`.
         */
        private String host;

        /**
         * SMTP server port.
         */
        private Integer port;

        /**
         * Login user of the SMTP server.
         */
        private String username;

        /**
         * Login password of the SMTP server.
         */
        private String password;

        /**
         * Protocol used by the SMTP server.
         */
        private String protocol = "smtp";

        /**
         * Default MimeMessage encoding.
         */
        private Charset defaultEncoding = StandardCharsets.UTF_8;
        /**
         * Additional JavaMail Session properties.
         */
        private Map<String, String> properties = new HashMap<>();

        /**
         * Session JNDI name. When set, takes precedence over other Session settings.
         */
        private String jndiName;

    }

    /**
     * 钉钉通知
     */
    private DingTalk ding = new DingTalk();

    /**
     * 日志清理任务
     */
    @Data
    public class DingTalk {

        /**
         * 是否开启
         */
        private boolean enable = true;

        /**
         * 钉钉令牌
         */
        private String token = "";

        /**
         * 钉钉地址
         */
        private String patch = "https://oapi.dingtalk.com/robot/send?access_token";
    }


}
